// top
// userpannel
let userpannel=document.querySelector('.top span:nth-child(4)')
let userpannel_showORhide=0
userpannel.onclick=(evt)=>{
    evt.stopPropagation();
    userpannel_showORhide++;
    let userpannelShowList=document.querySelector('.top span:nth-child(4) ul');
    let allwrap=document.querySelector('.allwrap')
    // 点击显示，再点隐藏
    if(userpannel_showORhide%2==1){
        userpannelShowList.style.display='block';
        allwrap.style.display='block'
        allwrap.style.height=getComputedStyle(document.querySelector('body')).height;
        allwrap.style.width=getComputedStyle(document.querySelector('body')).width;

    }else{
        userpannelShowList.style.display='none';
        allwrap.style.display='none'

    }
    // 点击任何地方隐藏此面板
    document.onclick=()=>{
        userpannelShowList.style.display='none';
        allwrap.style.display='none'
        userpannel_showORhide=0;
    }
}
// nav沾顶,返回顶部
let navfixed=document.querySelector('.nav_search_like')
let toTOP=document.querySelector('.toTOP')
window.onscroll=()=>{
    if (scrollY>88) {
        navfixed.style.position='fixed'
        toTOP.style.display='block'
        toTOP.onclick=()=>{
            scrollTo({top:0,behavior:'smooth'})
        }
    }else{
        navfixed.style.position='static'
        toTOP.style.display='none'
    }
}
// nav显示菜单
let nav_showORhide=0;
let showlist=document.querySelector('.nav_search_like .showlist>div')
showlist.onclick=(evt)=>{
    evt.stopPropagation();
    nav_showORhide++;
    let showlistUL=document.querySelector('.showlist>nav')
    let showlistIMG=document.querySelector('.showlist>div>img')
    if (nav_showORhide%2==1) {
        showlistUL.style.display='block'
        showlistIMG.style.transform='rotate(180deg)'
        showlist.style.background='#303237'
    }else{
        showlistUL.style.display='none'
        showlistIMG.style.transform='rotate(0deg)'
        showlist.style.background='#25262C'
    }
    document.onclick=()=>{
        showlistUL.style.display='none'
        showlistIMG.style.transform='rotate(0deg)'
        showlist.style.background='#25262C'
        nav_showORhide=0;
    }
}
// nav 战网点数
let navnum_showORhide=0;
let battlenetcount=document.querySelector('.nav_search_like .battlenetcount')
battlenetcount.onclick=(evt)=>{
    evt.stopPropagation();
    navnum_showORhide++;
    let showlistUL=document.querySelector('.battlenetcount>ul')
    let showlistIMG=document.querySelector('.battlenetcount>img')
    if (navnum_showORhide%2==1) {
        showlistUL.style.display='block'
        showlistIMG.style.transform='rotate(180deg)'
        battlenetcount.style.background='#303237'
    }else{
        showlistUL.style.display='none'
        showlistIMG.style.transform='rotate(0deg)'
        battlenetcount.style.background='#25262C'
    }
    document.onclick=()=>{
        showlistUL.style.display='none'
        showlistIMG.style.transform='rotate(0deg)'
        battlenetcount.style.background='#25262C'
        navnum_showORhide=0;
    }
}
// nav 搜索
let searchipt=document.querySelector('.nav_search_like .search input')
let searchClearBtn=document.querySelector('.nav_search_like .search button')
searchipt.onkeydown=(evt)=>{
    // 有值显示清空按钮
    if(searchipt.value!=''){
        searchClearBtn.style.opacity='1'
    }else{
        searchClearBtn.style.opacity='0'
    }
    // 回车搜索
    if (evt.keyCode==13) {
        if (searchipt.value=='') {
            alert('请输入搜索内容')
        }else location.href=`html/search.html?search=${searchipt.value}`
    }
}
searchClearBtn.onclick=()=>{
    searchipt.value='';
    searchClearBtn.style.opacity='0'
}
// 游戏图标展示部分
let gameicon=document.querySelector('.gameicon')
gameicon.onclick=(evt)=>{
    console.log(evt.target.nodeName);
    if(evt.target.nodeName.toLowerCase()=='img'){
        location.href=`../html/search.html?search=${evt.target.src}`
    }
}
// 登录
let loginbtn=document.querySelector('.top ul li:first-child button')
loginbtn.onclick=(evt)=>{
    evt.stopPropagation();
    location.href=`html/login.html`
}
// 注册
let resignbtn=document.querySelector('.top ul:last-child')
resignbtn.onclick=(evt)=>{
    evt.stopPropagation()
    location.href=`html/resign.html`
}
// 跳转购物车总览
let like=document.querySelector('.like')
like.onclick=()=>{
    location.href=`html/shopcar.html`
}
// 商品详情页
function shopifo(pid){
    location.href=`html/shopifo.html?pid=${pid}`
}
// 自动登录
function checklogin(){
    let username=localStorage.getItem('username')
    let password=localStorage.getItem('password')
    let loginURL=`http://jx.xuzhixiang.top/ap/api/login.php`
            axios.get(loginURL,{params:{
                username,
                password,
            }}).then(function(resolve){
                if(resolve.data.code==1){
                    localStorage.setItem('token',resolve.data.data.token)
                    document.querySelector('.top span:last-child').innerHTML=`
                    <a href="javaScript:">${username}</a>
                    <div class="user_triangle"></div>
                    <ul>
                        <li><img src="images/top/login_user.jpg" alt=""><a href="#">账户</a></li>
                        <li class='loginout'><img src="images/top/login_resign.jpg" alt=""><a href="#">退出登录</a></li>
                    </ul>
                    </a>`
                    document.querySelector('.loginout').onclick=()=>{
                        localStorage.clear();
                        location.href='index.html'
                    }
                }else{
                    localStorage.clear();
                }
            }).catch(function(reject){
                console.log(reject);
            });
}
checklogin();
let swiperBTN=document.querySelectorAll('.swiper-wrapper button')
console.log(swiperBTN);
swiperBTN.forEach((v,i)=>{
    v.onclick=()=>{
        location.href='html/pay.html'
    }
})